package cn.com.surker.system.controller;

import cn.com.surker.base.system.entity.SysLine;
import cn.com.surker.common.AbstractController;
import cn.com.surker.dto.system.SysLineDTO;
import cn.com.surker.spring.RestResultDto;
import cn.com.surker.system.model.CacheUser;
import cn.com.surker.system.service.SysLineService;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * 生产线控制层
 */
@RestController
@RequestMapping("/system/sysLine")
public class SysLineController extends AbstractController {

    @Resource
    private SysLineService sysLineService;
    @PostMapping(value = "/find-all")
    @ApiOperation(value = "查询生产线所有信息", tags = "生产线")
    public RestResultDto findAll(){
        List<SysLine> list = sysLineService.findAll();
        if (list == null || list.size() == 0)
            return RestResultDto.fail("没有数据");
        return RestResultDto.success(list);
    }

    @PostMapping(value = "/page")
    @ApiOperation(value = "分页方法", tags = "生产线")
    public RestResultDto pageData(@RequestBody SysLineDTO dto){
        return RestResultDto.success(sysLineService.page(dto));
    }

    @PostMapping(value = "/save")
    @ApiOperation(value = "新增方法", tags = "生产线")
    public RestResultDto save(@RequestBody SysLineDTO dto){
        CacheUser user = getUser();
        return RestResultDto.success(sysLineService.add(dto,user));
    }

    @PostMapping(value = "/update")
    @ApiOperation(value = "更新编辑方法", tags = "生产线")
    public RestResultDto update(@RequestBody SysLineDTO dto){
        CacheUser user = getUser();
        return RestResultDto.success(sysLineService.edit(dto,user));
    }

    @PostMapping(value = "/updatestatus")
    @ApiOperation(value = "更新状态方法", tags = "生产线")
    public RestResultDto updatestatus(@RequestBody SysLineDTO dto){
        CacheUser user = getUser();
        return RestResultDto.success(sysLineService.editStatus(dto.getId(),dto.getStatus(),user));
    }


}
